package com.example.demo.ip;


import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class NowTime {
    public static void main(String[] args) {
        //Date
        Date date = new Date();
        System.out.println(date);//Mon Aug 15 14:39:04 CST 2022
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(dateFormat.format(date));//2022-39-15 02:39:04
        String date1 = dateFormat.format(date);

        System.out.println();
        System.out.println();


        //Timestamp
        Timestamp time = new Timestamp(System.currentTimeMillis());
        System.out.println();
        System.out.println(time);
        System.out.println(Timestamp.valueOf(dateFormat.format(time)));
    }
}
